/*
 * DA5a.c
 *
 * Created: 4/20/2015 5:39:00 PM
 *  Author: David Hunt
 */ 

//DC MOTOR
#include <avr/io.h>

int main(void)
{
	//fast PWM with 0XFF as top, non-inverting mode, no prescale
	TCCR0A |= (1<<COM0A1) | (1<<WGM01) | (1<<WGM00);
	TCCR0B |= (1<<CS00);
	
	ADCSRA = 0x87;		//ENABLE ADC AND PRESCALE CK/128
	ADMUX = 0xC0;		//2.56V VREF, ADC0 SINGLE ENDED INPUT, DATA RIGHT JUSTIFIED
	DDRC = 0;			//SET PORTC AS INPUT FOR ADC
	DDRD = 0xFF;		//SET PORTD AS OUTPUT
	
    while(1)
    {
		ADCSRA |= (1<<ADSC);	//STARTING CONVERSION
		while((ADCSRA&(1<<ADIF))==0); //WAIT FOR CONVERSION TO FINISH
		OCR0A=ADCL;			//SET DUTYCYCLE BASED ON RESULT OF CONVERSION
    }
}